<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ph="http://java.sun.com/jsf/composite/pharmacy">

    <ui:define name="content">
        <h:form>

            <p:panel rendered="#{!storeTransferIssueController.printPreview}">

                <f:facet name="header" >                                  
                    <h:panelGrid columns="4"   >
                        <f:facet name="header">
                            <h:outputLabel value="Department :#{storeTransferIssueController.requestedBill.department.name}" />
                        </f:facet>
                        <p:autoComplete converter="stfcon" completeMethod="#{staffController.completeStaffWithoutDoctors}" styleClass="noPrintButton"
                                        forceSelection="true" placeholder="Hand Over To"
                                        var="w" itemLabel="#{w.person.name}" itemValue="#{w}"
                                        value="#{storeTransferIssueController.issuedBill.toStaff}" ></p:autoComplete>
                        <p:commandButton  value="Issue" action="#{storeTransferIssueController.settle}" ajax="false"  style="width: 150px; padding: 1px;border: 1px solid ; margin: auto;">
                        </p:commandButton>                        
                    </h:panelGrid>
                </f:facet>


                <p:dataTable styleClass="noBorder" var="bItm" scrollable="true" scrollHeight="250" 
                             value="#{storeTransferIssueController.billItems}" 
                             id="itemList" sortBy="#{bItm.searialNo}"  editable="true">  

                    <f:facet name="header">  
                        Requested Item 
                    </f:facet>  

                    <p:ajax event="rowEdit" listener="#{storeTransferIssueController.onEdit}"  />  
                    <p:ajax event="rowEditCancel" listener="#{storeTransferIssueController.onEdit}" /> 



                    <p:column headerText="Item Name" style="width: 50px!important;"  >                     
                        <h:outputText id="item" value="#{bItm.item.name}" >                                   
                        </h:outputText>
                    </p:column>  

                    <p:column headerText="Batch No"  style="width:50px!important;">  
                        <h:outputLabel value="#{bItm.pharmaceuticalBillItem.stock.itemBatch.batchNo}"/>                        
                    </p:column>  
                    <p:column headerText="Cost Rate"  style="width:50px!important;">  
                        <h:outputLabel value="#{bItm.pharmaceuticalBillItem.stock.itemBatch.purcahseRate}">                        
                            <f:convertNumber pattern="#,##0.00" />
                        </h:outputLabel>
                    </p:column>  

                    <p:column style="width:6%">  
                        <p:rowEditor />  
                    </p:column>

                    <p:column headerText="Qty" style="width:25px!important;">                   
                        <p:cellEditor>  
                            <f:facet name="output">  
                                <h:outputLabel value="#{bItm.pharmaceuticalBillItem.qtyInUnit}" />                               
                            </f:facet>                        
                            <f:facet name="input">  
                                <p:inputText autocomplete="off" id="qty" value="#{bItm.tmpQty}" >
                                    <f:ajax event="focus" render=":#{p:component('tab')}" execute="@this" listener="#{storeTransferIssueController.onFocus(bItm)}"/>
                                </p:inputText>
                            </f:facet>
                        </p:cellEditor>
                    </p:column>              

                    <p:column style="width: 10px!important;">
                        <p:commandButton value="Remove" ajax="false" action="#{storeTransferIssueController.remove(bItm)}">
                        </p:commandButton>
                    </p:column>
                </p:dataTable>  

                <p:spacer height="50"/>
                <ph:history/>

            </p:panel>
            <p:panel rendered="#{storeTransferIssueController.printPreview}">
                <p:commandButton ajax="false" action="store_transfer_request_list" actionListener="#{storeTransferIssueController.makeNull()}" value="Requested List"/>                    
                <p:commandButton value="Print" ajax="false" action="#" >
                    <p:printer target="gpBillPreview" ></p:printer>
                </p:commandButton>

                <p:panel   id="gpBillPreview"   >

                    <ph:transferIssue bill="#{storeTransferIssueController.issuedBill}"/>

                </p:panel>

            </p:panel>

        </h:form>
    </ui:define>  

</ui:composition>
